<script setup>
import { onMounted, ref } from "vue";
import {
  assetStatesControllerApi,
  dappOrderApi,
  getUserCurveDataApi,
  getPlatformDailyDataApi
} from "@/api/public";
import { useConfigStore } from "@/store/modules/config";
import { RouterLink } from "vue-router";

const useConfig = useConfigStore();

// CBT价格走势
const assetStatesControllerList = ref([]);
const assetStatesControllerFn = async () => {
  const res = await assetStatesControllerApi();
  assetStatesControllerList.value = res;
};

// 买卖订单列表
const dappOrderList = ref([]);
const dappOrderFn = async () => {
  const params = {
    page: 0,
    size: 50,
    sort: 1
  };
  const res = await dappOrderApi(params);
  dappOrderList.value = res;
};

// 个人收益曲线数据
const getUserCurveDataVal = ref();
const getUserCurveDataFn = async () => {
  const params = {
    address: useConfig.account,
    module_code: "HOLD_PROFIT"
  };
  const res = await getUserCurveDataApi(params);
  getUserCurveDataVal.value = res;
  console.log("res", res);
};

// 平台发放曲线数据
const getPlatformDailyDataVal = ref();
const getPlatformDailyDataFn = async () => {
  const params = {
    page: 0,
    size: 50
  };
  const res = await getPlatformDailyDataApi(params);
  getPlatformDailyDataVal.value = res;
  console.log("res", res);
};

const testVal = ref("");
onMounted(() => {
  testVal.value = navigator.userAgent || navigator.vendor || window.opera;
  // CBT价格走势
  // assetStatesControllerFn();
  // 买卖订单列表
  // dappOrderFn();
  // 个人收益曲线数据
  // getUserCurveDataFn();
  // 平台发放曲线数据
  // getPlatformDailyDataFn();
});
</script>

<template>
  <div class="app-container" style="color: #fff; padding: 20px">
    <div>
      {{ testVal }}
    </div>

    <h3>CBT价格走势</h3>
    <div v-for="(v, i) in assetStatesControllerList" :key="i">
      {{ v.created_at }} -{{ useConfig.web3.utils.fromWei(v.price, "ether") }}
    </div>

    <hr />
    <h3>买卖订单列表</h3>
    <div v-for="(v, i) in dappOrderList" :key="i" style="padding: 10px 0">
      <RouterLink :to="{ name: 'Exchange', query: { address: v.form_address } }"
        >跳转购买 {{ v.form_address }}</RouterLink
      >
    </div>
    <div>
      <RouterLink
        :to="{
          name: 'Exchange',
          query: { address: '0x38a2249BDE82A462d4480B7217C98b92A7C071D0' }
        }"
        >写死测试 跳转购买
        0x38a2249BDE82A462d4480B7217C98b92A7C071D0</RouterLink
      >
    </div>

    <hr />

    <h3>创建订单</h3>
    <RouterLink :to="{ name: 'BigvCreateOrder' }">跳转创建订单</RouterLink>

    <hr />

    <h3>个人收益曲线数据</h3>
    {{ getUserCurveDataVal }}

    <hr />

    <h3>平台发放曲线数据</h3>
    {{ getPlatformDailyDataVal }}
  </div>
</template>

<style lang="scss" scoped></style>
